package cn.shyouchi.wuguanjia.android.ui.statistic.page;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.base.BaseFragment;
import cn.shyouchi.wuguanjia.android.widget.CircularProgressBar;

/**
 * A simple {@link Fragment} subclass.
 */
public class MothStatisticFragment extends BaseFragment {

    MonthStatisticAdapter mAdapter;
    @BindView(R.id.rv_month_statistic)
    RecyclerView mRvMonthStatistic;


    List<String> mMonthStatisticEntities = new ArrayList<>();
    @BindView(R.id.tv_date)
    TextView mTvDate;
    @BindView(R.id.pro_rate)
    CircularProgressBar mProRate;
    @BindView(R.id.tv_leaving_rate)
    TextView mTvLeavingRate;
    @BindView(R.id.tv_newly_num)
    TextView mTvNewlyNum;
    @BindView(R.id.tv_leaving_num)
    TextView mTvLeavingNum;

    YearStatisticEntity.ResultMessageBean currentEntity;

    String projectId = "";



    public MothStatisticFragment() {
    }


    @Override
    public void initInjector() {

    }

    @Override
    public int initContentView() {
        return R.layout.fragment_moth_statistic;
    }

    @Override
    public void getBundle(Bundle bundle) {

    }

    @Override
    public void initUI(View view) {
        ButterKnife.bind(this, view);


        projectId = ((StatisticPageActivity) getActivity()).getProjectId();

        EventBus.getDefault().register(this);


        mAdapter = new MonthStatisticAdapter(mMonthStatisticEntities, projectId);
        mRvMonthStatistic.setAdapter(mAdapter);
        mRvMonthStatistic.setLayoutManager(new LinearLayoutManager(getContext()));

        mAdapter.setEmptyView(LayoutInflater.from(getContext()).inflate(R.layout.empty_view_layout, null));
        showEmpty(true);
    }

    @Override
    public void initData() {

    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onYearStatisticItemClick(YearStatisticEntity.ResultMessageBean entity) {
        showContent(true);
        mMonthStatisticEntities.clear();
        mMonthStatisticEntities.addAll(entity.getMonth());
        mAdapter.notifyDataSetChanged();
    }


    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

//    @OnClick({R.id.tv_newly_num, R.id.tv_leaving_num})
//    public void onClick(View view) {
//        switch (view.getId()) {
//            case R.id.tv_newly_num:
//                Intent intent = new Intent(getContext(), NewlyStaffActivity.class);
//                intent.putExtra("newly", currentEntity.getRecruits());
//                startActivity(intent);
//
//                break;
//            case R.id.tv_leaving_num:
////                startActivity(new Intent(getContext(), LeavingStaffActivity.class));
//                break;
//        }
//    }

}
